//
//  InputPurchaseDayView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/15.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "InputPurchaseDayView.h"

@interface InputPurchaseDayView ()
@property(nonatomic,strong)UIView *shadeView;

@end

@implementation InputPurchaseDayView{
    GLGWTextField * inputTextField;
}

-(id)initWithPopWindowView{
    if (self = [super initWithFrame:CGRectZero]) {
        self.layer.cornerRadius = 10.0;
        self.layer.masksToBounds = YES;
        _shadeView = [[UIView alloc]initWithFrame:kScreen_Bounds];
        _shadeView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
        _shadeView.tag = 1000;
        self.backgroundColor = [UIColor whiteColor];
        [self.shadeView addSubview:self];
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.shadeView);
            make.centerY.equalTo(self.shadeView).offset(-kHeightProportion_In_iPhoneTriploid(30));
            make.left.equalTo(self.shadeView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(50));
            make.right.equalTo(self.shadeView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(50));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(120)));
        }];
        //
        GLGWLabel * titLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self];
        titLabel.text = @"自定义截止时间";
        [titLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(15));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        }];
        //day
        GLGWLabel * dayLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self];
        dayLabel.text = @"天";
        [dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(30));
            make.centerY.equalTo(titLabel);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(20)));
        }];
        //
        inputTextField = [[GLGWTextField alloc] initTitlePlaceholder:@"天数" theFont:SYSTEMFONT(16) theTitColor:kColor_Rule_Black inSuperView:self];
        inputTextField.textAlignment = NSTextAlignmentRight;
        inputTextField.keyboardType =  UIKeyboardTypeNumberPad;
        [inputTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titLabel.mas_right).offset(kWidthProportion_In_iPhoneTriploid(5));
            make.right.equalTo(dayLabel.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(5));
            make.centerY.equalTo(titLabel);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(25)));
        }];
        //
        NSArray * titArr = @[@"取消",@"确定"];
        for (int i= 0; i<2; i++) {
            GLGWButton * dismissBut = [[GLGWButton alloc] initWithTitle:titArr[i] titleLableFont:SYSTEMFONT(16) titleLableColor:kColor_Rule_Yellow theCornerRadius:0 theBorderWidth:0.5 theBorderColor:[UIColor colorWithHexString:@"#EAEAEA"] backgroundColr:[UIColor whiteColor] inSuperView:self];
            if (i==0) {
                [dismissBut setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
            }
            [dismissBut mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.mas_left).offset((KScreenWidth - kWidthProportion_In_iPhoneTriploid(100))/2*i);
                make.bottom.equalTo(self);
                make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(50)));
                make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid((KScreenWidth - kWidthProportion_In_iPhoneTriploid(100))/2)));
            }];
            dismissBut.tag = 150+i;
            [dismissBut addTarget:self action:@selector(inPutAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        
    }
    return self;
}

-(void)inPutAction:(GLGWButton *)sender{
    if (sender.tag == 150) {
        [self dissmiss];
    }else{
        if ([inputTextField.text integerValue] == 0) {
            return;
        }
        if (self.Block_InpuetDay) {
            self.Block_InpuetDay([inputTextField.text integerValue]);
        }
        [self dissmiss];
    }
}

//显示
- (void)show {
    self.transform = CGAffineTransformMakeScale(0.8f, 0.8f);
    [UIView animateWithDuration:0.2 animations:^{
        [self dissmiss];
        self.transform = CGAffineTransformIdentity;
        [[UIApplication sharedApplication].keyWindow addSubview:self.shadeView];
    } completion:^(BOOL finished) {
    }];
}

- (void)dissmiss {
    NSEnumerator *subviewsEnum = [[UIApplication sharedApplication].keyWindow.subviews reverseObjectEnumerator];
    for (UIView *subview in subviewsEnum) {
        if (subview.tag == 1000) {
            [subview removeFromSuperview];
        }
    }
}

@end
